var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab: ["已完成", "未就诊/已取消"],

    current: null,
    userInfo: {}
  },
  tab: function(e) {
    var that = this
    var id = that.data.id
    var index = e.currentTarget.dataset.index
    console.log(index)
    var openid = wx.getStorageSync('openid')
    if (index == 0) {
      app.util.request({
        url: 'entry/wxapp/Selectdoctor2',
        data: {
          id: id,
        },
        success: function(res) {

          that.setData({
            selectdoctor2: res.data.data,
          })
        }
      })

    } else {
      app.util.request({
        url: 'entry/wxapp/Selectdoctor1',
        data: {
          id: id,
        },
        success: function(res) {
          console.log(res)
          that.setData({
            selectdoctor1: res.data.data,
          })
        }
      })
    }

    this.setData({
      current: e.currentTarget.dataset.index
    })
  },
  tab1: function(e) {
    var that = this
    var index = e.currentTarget.dataset.index
    var id = that.data.id
    app.util.request({
      url: 'entry/wxapp/Selectdoctororder',
      data: {
        id: id
      },
      success: function(res) {
        console.log(res)
        that.setData({
          selectdoctororder: res.data.data,
        })
      }
    })
    this.setData({
      current: null
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var that = this;
    var id = options.id
    that.setData({
      id: id
    })
    var userInfo = wx.getStorageSync('userInfo')
    that.setData({
      userInfo: userInfo
    })


    app.util.request({
      url: 'entry/wxapp/Selectdoctororder',
      data: {
        id: id
      },
      success: function(res) {
        console.log(res)
        that.setData({
          selectdoctororder: res.data.data,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  ddxqClick: function(e) {
    var id = e.currentTarget.dataset.id
    app.util.request({
      'url': 'entry/wxapp/Dmoney',
      data: {
        id: id,
      },
      success: function(res) {
        console.log(res)
        wx.navigateTo({
          url: '/hyb_yl/mysubpages/pages/ddxq/ddxq?id=' + id,
        })

      },
    })

  },
  look_detail(e) {
    var username = e.currentTarget.dataset.data
    var ksname = e.currentTarget.dataset.ks
    var money = e.currentTarget.dataset.money
    var phone = e.currentTarget.dataset.phone
    var tjtime = e.currentTarget.dataset.tjtime
    var yytime = e.currentTarget.dataset.yytime
    var dorder = e.currentTarget.dataset.dorder
    var sex = e.currentTarget.dataset.sex
    var age = e.currentTarget.dataset.age
    var zjid = e.currentTarget.dataset.zjid
    var hzid = e.currentTarget.dataset.hzid
    var useropenid = e.currentTarget.dataset.useropenid
    wx.navigateTo({
      url: '/hyb_yl/backstageGroceries/pages/patient_detail2/patient_detail2?username=' + username + '&ksname=' + ksname + '&money=' + money + '&phone=' + phone + '&tjtime=' + tjtime + '&yytime=' + yytime + '&dorder=' + dorder + '&sex=' + sex + '&age=' + age + '&zjid=' + zjid + '&hzid=' + hzid + '&useropenid=' + useropenid + '&xq=' + 0,
    })
  },
  // entird: function (e) {
  //   console.log(e)
  // },
  entird: function(e) {
    //确认就诊，改变参数zy_zhenzhuang为1
    var that = this;
    var selectdoctororder = that.data.selectdoctororder;
    console.log(selectdoctororder);
    var zy_id = e.currentTarget.dataset.id;
    var i = e.currentTarget.dataset.index;
    wx.showModal({
      content: '是否确认就诊',
      success: function(sm) {
        if (sm.confirm) {
          app.util.request({
            'url': 'entry/wxapp/Updatetype',
            data: {
              zy_id: zy_id,
            },
            success: function(res) {
              selectdoctororder[i].zy_zhenzhuang = 1;
              that.setData({
                selectdoctororder: selectdoctororder
              })
              console.log(res)
            },
          })
        } else if (sm.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  entird2: function(e) {
    //确认就诊，改变参数zy_zhenzhuang为1
    var that = this;
    var selectdoctor1 = that.data.selectdoctor1;
    console.log(selectdoctor1);
    var zy_id = e.currentTarget.dataset.id;
    var i = e.currentTarget.dataset.index;
    wx.showModal({
      content: '是否确认就诊',
      success: function(sm) {
        if (sm.confirm) {
          app.util.request({
            'url': 'entry/wxapp/Updatetype',
            data: {
              zy_id: zy_id,
            },
            success: function(res) {
              selectdoctor1[i].zy_zhenzhuang = 1;
              that.setData({
                selectdoctor1: selectdoctor1
              })
              console.log(res)
            },
          })
        } else if (sm.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  deldd: function(e) {
    var that = this;
    var selectdoctororder = that.data.selectdoctororder;
    var zy_id = e.currentTarget.dataset.id;
    var i = e.currentTarget.dataset.index;
    wx.showModal({
      content: '是否移除此订单',
      success: function(sm) {
        if (sm.confirm) {
          app.util.request({
            'url': 'entry/wxapp/Updatetype3',
            data: {
              zy_id: zy_id,
            },
            success: function(res) {
              //console.log(res)
              selectdoctororder.splice(i, 1);
              that.setData({
                selectdoctororder: selectdoctororder
              })
            },
          })
        } else if (sm.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  deldd1: function(e) {
    var that = this;
    var selectdoctor2 = that.data.selectdoctor2;
    var zy_id = e.currentTarget.dataset.id;
    var i = e.currentTarget.dataset.index;
    wx.showModal({
      content: '是否移除此订单',
      success: function(sm) {
        if (sm.confirm) {
          app.util.request({
            'url': 'entry/wxapp/Updatetype3',
            data: {
              zy_id: zy_id,
            },
            success: function(res) {
              console.log(res)
              selectdoctor2.splice(i, 1);
              that.setData({
                selectdoctor2: selectdoctor2
              })
            },
          })
        } else if (sm.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  deldd2: function(e) {
    var that = this;
    var selectdoctor1 = that.data.selectdoctor1;
    var zy_id = e.currentTarget.dataset.id;
    var i = e.currentTarget.dataset.index;
    wx.showModal({
      content: '是否移除此订单',
      success: function(sm) {
        if (sm.confirm) {
          app.util.request({
            'url': 'entry/wxapp/Updatetype3',
            data: {
              zy_id: zy_id,
            },
            success: function(res) {
              console.log(res)
              selectdoctor1.splice(i, 1);
              that.setData({
                selectdoctor1: selectdoctor1
              })
            },
          })
        } else if (sm.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
})